package co.yixiang.modules.shop.service.impl;

import co.yixiang.modules.shop.domain.YxStoreBonus;
import co.yixiang.modules.shop.repository.YxStoreBonusRepository;
import co.yixiang.modules.shop.service.YxStoreBonusService;
import co.yixiang.modules.shop.service.dto.YxStoreBonusDto;
import co.yixiang.modules.shop.service.dto.YxStoreBonusQueryCriteria;
import co.yixiang.modules.shop.service.mapper.YxStoreBonusMapper;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
// 默认不使用缓存
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import co.yixiang.utils.PageUtil;
import co.yixiang.utils.QueryHelp;

import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;

/**
 * @author frq
 * @date 2020-07-22
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YxStoreBonusServiceImpl implements YxStoreBonusService {
    @Autowired
    private YxStoreBonusRepository yxStoreBonusRepository;
    @Autowired
    private YxStoreBonusMapper yxStoreBonusMapper;


    @Override
    public Map<String, Object> queryAll(YxStoreBonusQueryCriteria criteria, Pageable pageable) {
        Page<YxStoreBonus> page = yxStoreBonusRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
        return PageUtil.toPage(page.map(yxStoreBonusMapper::toDto));
    }

    @Override
    public List<YxStoreBonusDto> queryAll(YxStoreBonusQueryCriteria criteria) {
        return yxStoreBonusMapper.toDto(yxStoreBonusRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
    }


}